//
//  OMMallCategoryCollectCell.m
//  OMENGO
//
//  Created by 梁尚嘉 on 2016/12/9.
//  Copyright © 2016年 Kamfat. All rights reserved.
//

#import "OMMallCategoryCollectCell.h"
#import "OMMallCategoryItem.h"
@implementation OMMallCategoryCollectCell
{
    OMMallCategoryItem *_item;
}

- (void)configure
{
    [super configure];

    [self makeConstraints];
}

- (void)makeConstraints
{

    
    UIView *containView =[UIView new];
    [self.contentView addSubview:containView];
    [containView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView.mas_centerY);
        make.centerX.equalTo(self.contentView.mas_centerX);
    }];

    [containView addSubview:self.imageView];
    [containView addSubview:self.label];

//    containView.backgroundColor = SM_orangeColor;

    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(@0);
        make.width.height.equalTo(@(SM_SIZE(70)));
    }];
    //self.imageView.backgroundColor = SM_thumeColor;

    [self.label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.top.equalTo(self.imageView.mas_bottom).offset(SM_SIZE(20));
        make.bottom.equalTo(@0);
    }];
    //self.contentView.backgroundColor = SM_waterBlueColor;

}

- (void)configureCellWithObj:(id)item
{
    _item = item;
    NSString *imageStr = _item.image;

    BOOL isWebImage = [imageStr rangeOfString:@"/"].length;
    isWebImage?({
        [self.imageView kt_imageWithURLStr:imageStr
                           placeHolder:[UIImage imageNamed:@"ic_mall_category_placehold_roundrect"]
                              withSize:CGSizeMake(OMMallCategoryCollectCell_size*3,
                                                  OMMallCategoryCollectCell_size*3)];
    }):({
        [self.imageView setImage:[UIImage imageNamed:imageStr]];
    });

    self.label.text = _item.name;
}

- (UILabel *)label
{
    if (!_label) {
        _label = [UILabel new];
        _label.font = SM_CFont(23);
        _label.textColor = SM_blackColor;
    }
    return _label;
}

- (UIImageView *)imageView
{
    if (!_imageView) {
        _imageView = [UIImageView new];
        _imageView.contentMode = UIViewContentModeScaleAspectFill;
    }
    return _imageView;
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{

}

- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [super touchesEnded:touches withEvent:event];
//    [self.imageView addInstanceScaleAnimationWithTargetScale:1.1 reverse:YES duration:.1];
    OMMallCategoryItem *item = _item;
    NaviPush(item.controller, @{@"title":item.name});
}


@end
